<!DOCTYPE html>
<html lang="zh-cn">
    <head>
        <meta charset="UTF-8">
        <title>新增页面</title>
        <link rel="stylesheet" href="/app/admin/component/pear/css/pear.css" />
        <link rel="stylesheet" href="/app/admin/component/jsoneditor/css/jsoneditor.css" />
        <link rel="stylesheet" href="/app/admin/admin/css/reset.css" />
    </head>
    <body>

        <form class="layui-form" action="">

            <div class="mainBox">
                <div class="main-container mr-5">
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label required">平台ID</label>
                        <div class="layui-input-block">
                            <input type="number" name="mall_id" value="12" required lay-verify="required" class="layui-input">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">商户ID</label>
                        <div class="layui-input-block">
                            <input type="number" name="mch_id" value="0" class="layui-input">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">一卡通名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="onecard_name" value="" class="layui-input">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">年卡发行批次</label>
                        <div class="layui-input-block">
                            <input type="text" name="batch_id" value="" class="layui-input">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">发行日期</label>
                        <div class="layui-input-block">
                            <input type="text" name="batch_date" value="" class="layui-input">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">关键字</label>
                        <div class="layui-input-block">
                            <input type="text" name="keyword" value="" class="layui-input">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">一卡通简介</label>
                        <div class="layui-input-block">
                            <textarea id="introduction"  name="introduction" class="layui-textarea"></textarea>
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">商品详情</label>
                        <div class="layui-input-block">
                            <textarea id="description" name="description" class="layui-textarea"></textarea>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">商品封面图</label>
                        <div class="layui-input-block">
                            <img class="img-3" src=""/>
                            <input type="text" style="display:none" name="pic_url" value="" />
                            <button type="button" class="pear-btn pear-btn-primary pear-btn-sm" id="pic_url" permission="app.admin.upload.image">
                                <i class="layui-icon layui-icon-upload"></i>图片
                            </button>
                            <button type="button" class="pear-btn pear-btn-primary pear-btn-sm" id="attachment-choose-a4gb9" permission="app.admin.upload.attachment">
                                <i class="layui-icon layui-icon-align-left"></i>选择图片
                            </button>
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">商品轮播图地址</label>
                        <div class="layui-input-block">
                            <input type="text" name="slider_pic_urls" value="" class="layui-input">
                        </div>
                    </div>
<!--                    <div class="layui-form-item">-->
<!--                        <label class="layui-form-label">商品轮播图地址</label>-->
<!--                        <div class="layui-input-block">-->
<!--                            <img class="img-3" src=""/>-->
<!--                            <input type="text" style="display:none" name="slider_pic_urls" value="" />-->
<!--                            <button type="button" class="pear-btn pear-btn-primary pear-btn-sm" id="slider_pic_urls" permission="app.admin.upload.image">-->
<!--                                <i class="layui-icon layui-icon-upload"></i>图片-->
<!--                            </button>-->
<!--                            <button type="button" class="pear-btn pear-btn-primary pear-btn-sm" id="attachment-slider_pic_urls" permission="app.admin.upload.attachment">-->
<!--                                <i class="layui-icon layui-icon-align-left"></i>选择图片1-->
<!--                            </button>-->
<!--                            <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">-->
<!--                                预览图：-->
<!--                                <div class="layui-upload-list" id="slider_pic_urls_prew"></div>-->
<!--                            </blockquote>-->
<!--                        </div>-->
<!--                    </div>-->
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">商品分类编号</label>
                        <div class="layui-input-block">
                            <input type="number" name="category_id" value="" class="layui-input">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">状态</label>
                        <div class="layui-input-block">
                            <input type="radio" name="status" value="0" title="未发行" checked>
                            <input type="radio" name="status" value="1" title="已发行" >
                            <input type="radio" name="status" value="2" title="已下架" >
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">绑卡须知</label>
                        <div class="layui-input-block">
                            <textarea id="content" name="content" class="layui-textarea"></textarea>
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">隐私协议</label>
                        <div class="layui-input-block">
                            <textarea id="ys_content" name="ys_content" class="layui-textarea"></textarea>
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">销售价格</label>
                        <div class="layui-input-block">
                            <input type="number" name="price" placeholder="单位使用：分" value="-1" class="layui-input">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">市场价</label>
                        <div class="layui-input-block">
                            <input type="number" name="market_price" placeholder="单位使用：分" value="" class="layui-input">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">成本价</label>
                        <div class="layui-input-block">
                            <input type="number" name="cost_price" placeholder="单位使用：分" value="-1" class="layui-input">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">是否必须使用优惠券</label>
                        <div class="layui-input-block">
                            <input type="radio" name="use_coupon" value="0" title="否" checked>
                            <input type="radio" name="use_coupon" value="1" title="是" >
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">赠送积分</label>
                        <div class="layui-input-block">
                            <input type="number" name="give_integral" value="0" class="layui-input">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">卡类型</label>
                        <div class="layui-input-block">
                            <select name="card_type" lay-verify="">
                                <option value="">请选择卡类型</option>
                                <option value="1">年卡</option>
                                <option value="2">季卡</option>
                                <option value="3">月卡</option>
                                <option value="10">转转卡</option>
                            </select>
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">有效期单位</label>
                        <div class="layui-input-block">
                            <input type="radio" name="valid_unit" value="Y" title="年" checked>
                            <input type="radio" name="valid_unit" value="M" title="月" >
                            <input type="radio" name="valid_unit" value="D" title="天" >
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">有效期</label>
                        <div class="layui-input-block">
                            <input type="number" name="valid_num" placeholder="单位使用：年、月、天,和单位配合使用" value="" class="layui-input">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">库存</label>
                        <div class="layui-input-block">
                            <input type="number" name="stock" value="0" class="layui-input">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">商品销量</label>
                        <div class="layui-input-block">
                            <input type="number" name="sales_count" value="0" class="layui-input">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">创建时间</label>
                        <div class="layui-input-block">
                            <input type="text" class="layui-input"  name="create_time" id="create_time" placeholder="yyyy-MM-dd">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">更新时间</label>
                        <div class="layui-input-block">
                            <input type="text" name="update_time" id="update_time" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">创建人</label>
                        <div class="layui-input-block">
                            <input type="text" name="creator" value="" class="layui-input">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">更新人</label>
                        <div class="layui-input-block">
                            <input type="text" name="updater" value="" class="layui-input">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">是否删除</label>
                        <div class="layui-input-block">
                            <input type="radio" name="deleted" value="0" title="否" checked>
                            <input type="radio" name="deleted" value="1" title="是" >
                        </div>
                    </div>
<!--                    <div class="layui-form-item" style="width:200%;">-->
<!--                        <label class="layui-form-label">商品轮播图</label>-->
<!--                        <div>-->
<!--                            <ul class="upload-ul clearfix">-->
<!--                                <li class="upload-pick">-->
<!--                                    <div class="webuploader-container clearfix" id="goods_banners"></div>-->
<!--                                </li>-->
<!--                            </ul>-->
<!--                            <p>-->
<!--                                <button style="margin-left:110px;" type="button" class="layui-btn" id="upload-btn-banners">开始上传</button>-->
<!--                            </p>-->
<!--                        </div>-->
<!--                    </div>-->
                    <div class="layui-form-item">
                        <label class="layui-form-label">租户编号</label>
                        <div class="layui-input-block">
                            <input type="number" name="tenant_id" value="0" class="layui-input">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label required">生效日期类型</label>
                        <div class="layui-input-block">
                            <input type="radio" name="validity_type" value="1" title="固定日期区间" >
                            <input type="radio" name="validity_type" value="2" title="购买/兑换之后"  checked >
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">固定日期-生效日期范围</label>
                                <div class="layui-inline" id="test6">
                                    <div class="layui-input-inline">
                                        <input type="text" autocomplete="off" name="valid_start_time" id="valid_start_time" class="layui-input" placeholder="开始日期">
                                    </div>
                                    <div class="layui-form-mid">-</div>
                                    <div class="layui-input-inline">
                                        <input type="text" autocomplete="off" name="valid_end_time" id="valid_end_time" class="layui-input" placeholder="结束日期">
                                    </div>
                                </div>
                            </div>
                        </div>


                    </div>
                    

                    <div class="layui-form-item">
                        <label class="layui-form-label required">是否删除</label>
                        <div class="layui-input-block">
                            <input type="radio" name="is_delete" value="0" title="否" checked>
                            <input type="radio" name="is_delete" value="1" title="是" >
                        </div>
                    </div>

                    
                </div>
            </div>

            <div class="bottom">
                <div class="button-container">
                    <button type="submit" class="pear-btn pear-btn-primary pear-btn-md" lay-submit=""
                        lay-filter="save">
                        提交
                    </button>
                    <button type="reset" class="pear-btn pear-btn-md">
                        重置
                    </button>
                </div>
            </div>
            
        </form>
        <!-- 引入jQuery -->
        <script src="/app/admin/component/layui/layui.js?v=2.8.12"></script>
        <script src="/app/admin/component/pear/pear.js"></script>
        <script src="/app/admin/component/jsoneditor/jsoneditor.js"></script>
        <script src="/app/admin/admin/js/permission.js"></script>
<!--        <script src="/app/admin/admin/js/diyUpload.js"></script>-->
        
        <script>

            // 相关接口
            const INSERT_API = "/app/admin/tejian-onecard-info/insert";
            layui.define(['layer', 'carousel'], function (exports) {
                var $ = layui.jquery;
                var layer = layui.layer;

                //上传商品轮播图
                // var goods_banners = '';
                // var $bannerUpload = $('#goods_banners').diyUpload({
                //     url:'/app/admin/upload/image',
                //     success:function(resp) {
                //         if(resp.error == 0){
                //             goods_banners += resp.url + ',';
                //         }
                //     },
                //     error:function(err) { },
                //     buttonText : '',
                //     accept: {
                //         title: "Images",
                //         extensions: 'gif,jpg,jpeg,bmp,png'
                //     },
                //     thumb:{
                //         width:120,
                //         height:90,
                //         quality:100,
                //         allowMagnify:true,
                //         crop:true,
                //         type:"image/jpeg"
                //     }
                // });

            });



            layui.use('laydate', function() {
                var laydate = layui.laydate;

                //常规用法
                laydate.render({
                    elem: '#create_time'
                });
                //常规用法
                laydate.render({
                    elem: '#update_time'
                });
                //日期范围
                laydate.render({
                    elem: '#test6'
                    //设置开始日期、日期日期的 input 选择器
                    //数组格式为 2.6.6 开始新增，之前版本直接配置 true 或任意分割字符即可
                    ,range: ['#valid_start_time', '#valid_end_time']
                });
            })
            // 字段 头像 avatar
            layui.use(["upload", "layer"], function() {
                let input = layui.$("#pic_url").prev();
                input.prev().attr("src", input.val());
                layui.$("#attachment-choose-a4gb9").on("click", function() {
                    parent.layer.open({
                        type: 2,
                        title: "选择附件",
                        content: "/app/admin/upload/attachment?ext=jpg,jpeg,png,gif,bmp",
                        area: ["95%", "90%"],
                        success: function (layero, index) {
                            parent.layui.$("#layui-layer" + index).data("callback", function (data) {
                                input.val(data.url).prev().attr("src", data.url);
                            });
                        }
                    });
                });
                layui.upload.render({
                    elem: "#pic_url",
                    url: "/app/admin/upload/image",
                    acceptMime: "image/gif,image/jpeg,image/jpg,image/png",
                    field: "__file__",
                    done: function (res) {
                        if (res.code > 0) return layui.layer.msg(res.msg);
                        this.item.prev().val(res.data.url).prev().attr("src", res.data.url);
                    }
                });
                //多图片上传
                layui.upload.render({
                    elem: '#slider_pic_urls'
                    ,url: '/app/admin/upload/image' //此处配置你自己的上传接口即可
                    ,acceptMime: "image/gif,image/jpeg,image/jpg,image/png"
                    ,multiple: true
                    ,before: function(obj){
                        //预读本地文件示例，不支持ie8
                        // obj.preview(function(index, file, result){
                        //     // console.log(result);
                        //     parent.layui.$('#slider_pic_urls_prew').append('<img src="'+ result +'" alt="'+ file.name +'" class="layui-upload-img">')
                        // });
                    }
                    ,done: function(res){
                        //上传完毕
                        if (res.code > 0) return layui.layer.msg(res.msg);
                        console.log(res,parent.layui.$('#slider_pic_urls_prew'))
                        parent.layui.$('#slider_pic_urls_prew').append('<img src="'+ res.data.url +'" class="layui-upload-img">')

                    }
                });
                let input1 = layui.$("#slider_pic_urls").prev();
                input1.prev().attr("src", input.val());
                layui.$("#attachment-slider_pic_urls").on("click", function() {
                    parent.layer.open({
                        type: 2,
                        title: "选择附件",
                        content: "/app/admin/upload/attachment?ext=jpg,jpeg,png,gif,bmp",
                        area: ["95%", "90%"],
                        success: function (layero, index) {
                            parent.layui.$("#layui-layer" + index).data("callback", function (data) {
                                input.val(data.url).prev().attr("src", data.url);
                            });
                        }
                    });
                });
            });

            //富文本编辑器
            layui.use(['tinymce'], function() {
                layui.tinymce.render({
                    selector: "#content",
                    setup: function(editor){
                        editor.on('change', function (){
                            editor.save();
                        });
                    },
                }, function(e){
                    console.log(e);
                });
                layui.tinymce.render({
                    selector: "#ys_content",
                    setup: function(editor){
                        editor.on('change', function (){
                            editor.save();
                        });
                    },
                }, function(e){
                    console.log(e);
                });
                layui.tinymce.render({
                    selector: "#description",
                    setup: function(editor){
                        editor.on('change', function (){
                            editor.save();
                        });
                    },
                }, function(e){
                    console.log(e);
                });

                layui.tinymce.render({
                    selector: "#introduction",
                    setup: function(editor){
                        editor.on('change', function (){
                            editor.save();
                        });
                    },
                }, function(e){
                    console.log(e);
                });

            })
            
            // 字段 创建时间 create_time
            layui.use(["laydate"], function() {
                layui.laydate.render({
                    elem: "#create_time",
                    type: "datetime",
                });
            })
            
            // 字段 更新时间 update_time
            layui.use(["laydate"], function() {
                layui.laydate.render({
                    elem: "#update_time",
                    type: "datetime",
                });
            })
            
            // 字段 固定日期-生效开始时间 valid_start_time
            layui.use(["laydate"], function() {
                layui.laydate.render({
                    elem: "#valid_start_time",
                    type: "datetime",
                });
            })
            
            // 字段 固定日期-生效结束时间 valid_end_time
            layui.use(["laydate"], function() {
                layui.laydate.render({
                    elem: "#valid_end_time",
                    type: "datetime",
                });
            })
            
            // 字段 created_at created_at
            layui.use(["laydate"], function() {
                layui.laydate.render({
                    elem: "#created_at",
                    type: "datetime",
                });
            })
            
            //提交事件
            layui.use(["form", "popup"], function () {
                // 字段验证允许为空
                layui.form.verify({
                    phone: [/(^$)|^1\d{10}$/, "请输入正确的手机号"],
                    email: [/(^$)|^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/, "邮箱格式不正确"],
                    url: [/(^$)|(^#)|(^http(s*):\/\/[^\s]+\.[^\s]+)/, "链接格式不正确"],
                    number: [/(^$)|^\d+$/,'只能填写数字'],
                    date: [/(^$)|^(\d{4})[-\/](\d{1}|0\d{1}|1[0-2])([-\/](\d{1}|0\d{1}|[1-2][0-9]|3[0-1]))*$/, "日期格式不正确"],
                    identity: [/(^$)|(^\d{15}$)|(^\d{17}(x|X|\d)$)/, "请输入正确的身份证号"]
                });
                layui.form.on("submit(save)", function (data) {
                    layui.$.ajax({
                        url: INSERT_API,
                        type: "POST",
                        dateType: "json",
                        data: data.field,
                        success: function (res) {
                            if (res.code) {
                                return layui.popup.failure(res.msg);
                            }
                            return layui.popup.success("操作成功", function () {
                                parent.refreshTable();
                                parent.layer.close(parent.layer.getFrameIndex(window.name));
                            });
                        }
                    });
                    return false;
                });
            });

        </script>

    </body>
</html>
